/*
 * client_app.h
 */

#ifndef CLIENT_APP_H_
#define CLIENT_APP_H_

#include <iostream>
#include <string>
#include "../../common/src/message_queue.h"
#include "../../common/src/session.h"
#include "../../common/src/synchro_list.h"
#include "../../common/src/synchro_vector.h"
#include "../../common/src/socket.h"
#include "app_listener.h"
#include "engine.h"
#include "campaign_info.h"
#include "game_info.h"

class ClientApp {
public:
    ClientApp();
    ~ClientApp();
    void connect(std::string username, std::string& ipaddr, int port);
    void exec();
    void exit();
    void requestAbortGame();
    void requestCreateGame(std::string name, std::string campaignID);
    void requestJoinGame(std::string gameID);
    void requestStartGame();
    void requestGamesList();
    //void listCampaigns();
    int onCmd();
    bool isRunning();
    bool isConnected();
    MessageQueue& getMessageQueue();
    SynchroVector<GameInfo*>& getGames();
    SynchroVector<CampaignInfo*>& getCampaigns();
    SynchroList<AppListener*>& getListeners();
    void addListener(AppListener* listener);
    void removeListener(AppListener* listener);
private:
    static const std::string CMD_EXIT;
    static const std::string CMD_ABORT_GAME;
    static const std::string CMD_CREATE_GAME;
    static const std::string CMD_JOIN_GAME;
    static const std::string CMD_START_GAME;
    static const std::string CMD_LIST_GAMES;
    static const std::string CMD_LIST_CAMPAIGNS;
    bool running;
    bool connected;
    Socket* sock;
    Session* session;
    MessageQueue q;
    std::string username;
    SynchroList<AppListener*> listeners;
    SynchroVector<GameInfo*> games;
    SynchroVector<CampaignInfo*> campaigns;
    Engine engine;
    Thread t_engine;
    void loadCampaigns(Message* msg);
};

#endif //CLIENT_APP_H

//{+}
